package edu.nuist.javaProjct.view;

import edu.nuist.javaProjct.dao.StudentDatasourceDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EditDataModel {
    private JTextField uuidField;
    private JButton editBtn;

    private JTextField nameField;

    public JPanel editDataModel;

    private final StudentDatasourceDao studentBasicDao=new StudentDatasourceDao();

    public EditDataModel() {
        editBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String studentUUID = uuidField.getText();
                if (studentUUID.equals("")){
                    JOptionPane.showMessageDialog(editDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                    return ;
                }

                String studentName = nameField.getText();
                if (studentName.equals("")){
                    JOptionPane.showMessageDialog(editDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                    return ;
                }
                int result = studentBasicDao.updateData(studentUUID, studentName);

                if(result==1){
                    JOptionPane.showMessageDialog(editDataModel,"success");
                }else {
                    JOptionPane.showMessageDialog(editDataModel,"重新输入");
                }
            }
        });

    }
}
